// src/store/store.js
import { createStore } from "vuex";
import ModuleUser from "./user.js";
const store = createStore({
  state: {
    fileNames: [],
    count: 0,
    selectedData: null, // 添加 selectedData
  },
  mutations: {
    increment(state) {
      state.count++;
    },
    setFileNames(state, fileNames) {
      state.fileNames = fileNames;
    },
    setSelectedData(state, data) {
      // 添加 setSelectedData mutation
      state.selectedData = data;
    },
  },
  actions: {
    updateFileNames({ commit }, fileNames) {
      commit("setFileNames", fileNames);
      console.log("全局状态已更新", fileNames);
    },
    incrementAsync({ commit }) {
      setTimeout(() => {
        commit("increment");
      }, 1000);
    },
    setSelectedData({ commit }, data) {
      // 添加 setSelectedData action
      commit("setSelectedData", data);
    },
  },
  getters: {
    doubleCount: (state) => state.count * 2,
  },
  modules: {
    user: ModuleUser,
  },
});

export default store; // 确保这是一个默认导出
